<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<% String path = request.getContextPath(); %>
<%
	//通用标准地区级联
	//标准地区需要显示省 市 县 到哪个级,配置分为 1(省) 2(市) 3(县) 默认为省市县  
	String sysStdRegionDefShowLvl = request.getParameter("sysStdRegionDefShowLvl");
	if(sysStdRegionDefShowLvl == null){
		sysStdRegionDefShowLvl = "3";//默认
	}
	//可以根据需要填写省市县的标签名称,不写则默认
	String sysStdRegionProvCdNm = request.getParameter("sysStdRegionProvCdNm");//省名称
	String sysStdRegionCityCdNm = request.getParameter("sysStdRegionCityCdNm");//市名称
	String sysStdRegionDistCdNm = request.getParameter("sysStdRegionDistCdNm");//县名称
	 
	if(sysStdRegionProvCdNm == null){
		sysStdRegionProvCdNm = "省份";//默认
	}
	
	if(sysStdRegionCityCdNm == null){
		sysStdRegionCityCdNm = "城市";//默认
	}
	
	if(sysStdRegionDistCdNm == null){
		sysStdRegionDistCdNm = "区\\县";//默认
	}
	
%>
				<select name="regStdProvCd" id="regStdProvCd" value="${rgnPrCdNm }" placeholder="请选择" validate="{required:true}">
                </select>
				<span class="requiredSymbol">*</span>
				<select name="regStdCityCd" id="regStdCityCd" value="${rgnCyCdNm }" placeholder="请选择" validate="{required:true}">
                </select>
                <span class="requiredSymbol">*</span>
                <select name="regStdDistCd" id="regStdDistCd" value="${rgnCountyNm }" placeholder="请选择" validate="{required:true}">
                </select>
				<span class="requiredSymbol">*</span>
		        <input type="hidden" id="sysStdRegionDefShowLvl" value="<%=sysStdRegionDefShowLvl%>"/> 
		
<script type="text/javascript">

//加载后调用
$(function() {
	  initSysStdComboxEvent();//初始化下拉框数据
	  initSysStdShowLevel();//初始化显示级
	  initSysStdProvCombox();//初始化省
});

//获取显示级
var _sysStdRegionDefShowLvl = $("#sysStdRegionDefShowLvl").val();

//定义修改时回显值,需要调用页面在回显值的时候改变这几个值
var _sysStdProvCdUpdateValue = "";//省
var _sysStdCityCdUpdateValue = "";//市
var _sysStdDistCdUpdateValue = "";//县

//初始化显示级
function initSysStdShowLevel(){
	//判断rgnLvl参数  1:省   2:省市   3:省市县
	if (_sysStdRegionDefShowLvl == 1) {
		$("#regStdCityCd_parent_div_id").remove();
		$("#regStdDistCd_parent_div_id").remove();
	} else if (_sysStdRegionDefShowLvl == 2) {
		$("#regStdDistCd_parent_div_id").remove();
	}
}

//初始化下拉框数据
function initSysStdComboxEvent(){
	
	//省事件
	$("#regStdProvCd").change(function(event) {
        var rgnId = $(liger.get("regStdProvCd").element).find(':selected').attr("rgnId");
	        clearSysStdRegionSelectData("regStdCityCd");//清空市
	        clearSysStdRegionSelectData("regStdDistCd");//清空区\县
        if (StringUtils.isNotEmpty(rgnId)) {
        	//如果大于等于2级则执行赋值操作
        	if(_sysStdRegionDefShowLvl > 1 ){
        		getSysStdRegionRemoteData(rgnId, "regStdCityCd", _sysStdCityCdUpdateValue);
        	}
		}
    });
	
	//市事件
	$("#regStdCityCd").change(function(event) {
        var rgnId = $(liger.get("regStdCityCd").element).find(':selected').attr("rgnId");
		clearSysStdRegionSelectData("regStdDistCd");//清空区\县
        if (StringUtils.isNotEmpty(rgnId)) {
        	//如果大于等于2级则执行赋值操作
        	if(_sysStdRegionDefShowLvl > 2){
        		getSysStdRegionRemoteData(rgnId, "regStdDistCd", _sysStdDistCdUpdateValue);
        	}
		}
    });
}

//初始化省
function initSysStdProvCombox(){
	//发送请求获取省级区域
	$.ajax({
		type : 'post',
		dataType : 'json',
		url : '<%=path%>/system/sysstdregion/searchProvinceRegion.do',
		success:function(msg){
			 if(msg.success == 1){
				 setSysStdRegionSelectData("regStdProvCd",msg.data, _sysStdProvCdUpdateValue);
			 }else{
				 UIUtils.alertError(msg.info);
			 }
		}
	});
}

//设置下拉框数据
function getSysStdRegionRemoteData(_rgnPid, selectId, _backVal){
	if(StringUtils.isEmpty(_rgnPid) || StringUtils.isEmpty(selectId)){
		return;
	}
	$.ajax({
		type: 'post',
		dataType:'json',
		data:{rgnPid:_rgnPid},
		url: '<%=path%>/system/sysstdregion/searchRegionByRgnPid.do',
		success:function(msg){
			 if(msg.success == 1){
				 if(msg.data){
	    			 setSysStdRegionSelectData(selectId,msg.data, _backVal);
				 }else{
					 clearSysStdRegionSelectData(selectId);//市
				 }
			 }else{
				 UIUtils.alertError(msg.info);
			 }
		}
	});
}


//设置标准地址下拉框值
function setSysStdRegionSelectData(_id, data, _backVal){//backVal 回显值(要选中的值)
	$("#"+_id).empty();//1
	var option = "";
	 $.each(data,function(index,obj) {
		 if(index == 0){
			 option = "<option rgnId='"+obj.rgnId+"' value='"+obj.rgnId+"' selected>"+obj.value+"</option>";
		 }else{
			 option = "<option rgnId='"+obj.rgnId+"' value='"+obj.rgnId+"'>"+obj.value+"</option>";
		 }
		 $(option).appendTo("#"+_id);
	 });
	 if(StringUtils.isNotEmpty(_backVal)|| _backVal!= ""){
		 liger.get(_id).setValue(_backVal);
	 }
	 liger.get(_id).setSelect();
}

//清空下拉框值
  function clearSysStdRegionSelectData(_id){
	$("#"+_id).empty();//1
	liger.get(_id).clear();//2
	liger.get(_id).setSelect();//3
}  

//调用页面回显值时需要设置值
function setSysStdProvCdUpdateValue(_val){//设置省
	_sysStdProvCdUpdateValue = _val;
}

//调用页面回显值时需要设置值
function setSysStdCityCdUpdateValue(_val){//设置市
	_sysStdCityCdUpdateValue = _val;
}

//调用页面回显值时需要设置值
function setSysStdDistCdUpdateValue(_val){//设置县
	_sysStdDistCdUpdateValue = _val;
}

//调用页面回显值时需要调用事件
function setSysStdProvCdChange(){//省
	$("#regStdProvCd").change();
}
//调用页面回显值时需要调用事件
function setSysStdCityCdChange(){//市
	$("#regStdCityCd").change();
}
//获取区域下拉框选中值
function getRgnProvCd(){ //省
	var provSelectObj = liger.get("regStdProvCd");
	var _provCd = provSelectObj.getValue();
	return _provCd;
}
function getRgnCityCd(){ //市
	var citySelectObj = liger.get("regStdCityCd");
	var _cityCd = citySelectObj.getValue();
	return _cityCd;
}
function getRgnCountyCd(){ //县/区
	var countySelectObj = liger.get("regStdDistCd");
	var _countyCd = countySelectObj.getValue();
	return _countyCd;
}
</script>

